package app.service.order;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import app.model.order.OrderRecord;
import app.util.ClassUtil;
import app.util.StringUtil;
import base.PageInfo;
import base.dao.HibernateDao;
import base.service.BaseService;

@Service
public class OrderRecordService extends BaseService {

	@Autowired
	private HibernateDao<OrderRecord> hibernateDao;
	
	@Override
	public HibernateDao<OrderRecord> getDao() {
		return this.hibernateDao;
	}
	
	/**
	 * 查询商品
	 * @param pageInfo
	 * @param goodsName 
	 * @return
	 */
	public PageInfo queryByPage(PageInfo pageInfo, String orderNo,String orderStatus) {
		String sql = "select * FROM order_record a";
		if(StringUtil.isNotEmpty(orderNo)){
			sql += " and a.order_no like '%"+orderNo+"%'";
		}
		PageInfo page = getDao().queryPageListBySql(pageInfo, sql);
		return page;
	}

	public void saveEntity(OrderRecord orderRecord) {
		getDao().save(orderRecord);
	}

	public void updateEntity(OrderRecord orderRecord) {
		getDao().mergeAndUpdate(orderRecord);
	}

	public Map<String, Object> queryEntityById(String id) {
		String sql = "select * from goods_base_use_view a where a.id = '"+id+"'";
		Map<String, Object> map = getDao().queryMapBySql(sql);
		Map<String, Object> humpNamed = ClassUtil.toHumpNamed(map);
		return humpNamed;
	}

	public void delEntity(String ids) {
		if(!StringUtils.isEmpty(ids)){
			String[] idsArray = ids.split(",");
			for (int i = 0; i < idsArray.length; i++) {
				OrderRecord gb = new OrderRecord();
				gb.setId(idsArray[i]);
				getDao().del(gb);
			}
		}
	}
}
